import request from "@/request/request.ts";
import { pageParamsInterface } from "@/views/product/trademark/interface/interface.ts";
import { responseBaseSaleAttribute, responseSaleAttribute, responseSpuIMageList, responseSpuInfo, sku, spu } from "@/api/product/spuApi/interface.ts";


enum Enum {
  fetchSpuList = "/admin/product",
  deleteSpu = "/admin/product/deleteSpu",
  fetchTrademarkList = "/admin/product/baseTrademark/getTrademarkList",
  fetchSpuImageList = "/admin/product/spuImageList",
  fetchSpuSaleAttributeList = "/admin/product/spuSaleAttrList",
  fetchBaseSaleAttrList = "/admin/product/baseSaleAttrList",
  addSpu = "/admin/product/saveSpuInfo",
  updateSpu = "/admin/product/updateSpuInfo",
  addSku = "/admin/product/saveSkuInfo",
  findSkuList = "/admin/product/findBySpuId"
}

/* 获取spu的接口 */
export const fetchSpuListAPI: (pageParams: pageParamsInterface, category3Id: number | string) => Promise<responseSpuInfo> = (pageParams: pageParamsInterface, category3Id: number | string): Promise<responseSpuInfo> => {
  return request({
    url: `${Enum.fetchSpuList}/${pageParams.page}/${pageParams.limit}`,
    params: {
      category3Id,
    },
  });
};
/* 删除spu的接口 */
export const deleteSpuAPI: (spuId: number) => Promise<any> = (spuId: number): Promise<any> => {
  return request({
    url: `${Enum.deleteSpu}/${spuId}`,
    method: "DELETE",
  });
};
/* 获取spu所有品牌的接口 */
export const fetchTrademarkListAPI: () => Promise<any> = (): Promise<any> => {
  return request({
    url: Enum.fetchTrademarkList,
    method: "GET",
  });
};
/* 获取spu已有图片的接口 */
export const fetchSpuImageListAPI: (spuId: number) => Promise<responseSpuIMageList> = (spuId: number): Promise<responseSpuIMageList> => {
  return request({
    url: `${Enum.fetchSpuImageList}/${spuId}`,
    method: "GET",
  });
};
/* 获取spu已有的销售属性的接口 */
export const fetchSpuSaleAttributeListAPI: (spuId: number) => Promise<responseSaleAttribute> = (spuId: number): Promise<responseSaleAttribute> => {
  return request({
    url: `${Enum.fetchSpuSaleAttributeList}/${spuId}`,
    method: "GET",
  });
};
/* 获取spu所有的销售属性的接口 */
export const fetchBaseSaleAttributeListAPI: () => Promise<responseBaseSaleAttribute> = (): Promise<responseBaseSaleAttribute> => {
  return request({
    url: `${Enum.fetchBaseSaleAttrList}`,
    method: "GET",
  });
};

/* 添加或修改spu的接口 */
export const addSpuOrUpdateSpuAPI: (data: spu) => Promise<void> = (data: spu): Promise<void> => {
  if (data.id) {
    return request({
      url: Enum.updateSpu,
      method: "POST",
      data,
    });
  } else {
    return request({
      url: Enum.addSpu,
      method: "POST",
      data,
    });
  }
};

/* 添加sku的接口 */
export const addSkuAPI = (data: sku) => {
  return request({
    url: Enum.addSku,
    method: "POST",
    data,
  });
};

/* 查找sku列表的接口 */
export const findSkuList = (spuId: number | string):Promise<any> => {
  return request({
    url: `${Enum.findSkuList}/${spuId}`,
    method: "GET",
  });
};
